#include <stdio.h>
#include <string.h>
#include <algorithm>
#define maxn 25
#define maxm 100

using namespace std;

int n, m;
int ind[maxn], next[maxm * 2], to[maxm * 2], p;
int hash[maxn], hash2[maxn];
int code[maxn], code2[maxn];
int codes[maxn], codep;

void getcode (int k)
{
	for (int i = 0; i < n; i ++)
		code[i] = 123456789;
	for (int i = 0; i < n + n; i ++)
	{
		for (int j = 0; j < n; j ++)
			code2[j] = code[j];
		for (int j = 0; j < n; j ++)
		{
			code[j] = 654321987;
			codep = 0;
			for (int l = ind[j]; l != -1; l = next[l])
				codes[codep ++] = code2[to[l]];
			sort(codes, codes + codep);
			for (int l = 0; l < codep; l ++)
				code[j] = code[j] * 147 ^ codes[l];
		}

		code[k] ^= 88888888;
	}
	hash[k] = code[k];
}

void gethash ()
{
	p = 0;
	for (int i = 0; i < n; i ++)
		ind[i] = -1;
	for (int i = 0; i < m; i ++)
	{
		int a, b;

		scanf("%d%d", &a, &b);
		a --;
		b --;

		next[p] = ind[a];
		to[p] = b;
		ind[a] = p ++;

		next[p] = ind[b];
		to[p] = a;
		ind[b] = p ++;
	}

	for (int i = 0; i < n; i ++)
		getcode (i);
}

int main ()
{
	int t;

	for (scanf("%d", &t); t > 0; t --)
	{
		scanf("%d%d", &n, &m);
		gethash ();
		memcpy (hash2, hash, sizeof(hash));
		gethash ();
		
		sort(hash, hash + n);
		sort(hash2, hash2 + n);
		
		int ok = 1;
		for (int i = 0; i < n; i ++)
			if (hash[i] != hash2[i])
				ok = 0;
		if (ok)
			printf("same\n");
		else
			printf("different\n");
	}

	return 0;
}